/**
 * 0047
 *  
 * @Author : roryrywang
 * @DateTime : 2024/8/15 23:13
 */

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

class Solution {
public:
    vector<int> tmp;
    vector<vector<int>> res;

    void dfs(vector<int> &nums, vector<bool> &used) {
        if (tmp.size() == nums.size()) {
            res.push_back(tmp);
            return;
        }
        for (int i = 0; i < nums.size(); ++i) {
            if (!used[i]) {
                if (i > 0 && nums[i] == nums[i - 1] && !used[i - 1]) continue;
                tmp.push_back(nums[i]);
                used[i] = true;
                dfs(nums, used);
                tmp.pop_back();
                used[i] = false;
            }
        }
    }

    vector<vector<int>> permuteUnique(vector<int> &nums) {
        sort(nums.begin(), nums.end());
        vector<bool> used(nums.size());
        for (int i = 0; i < used.size(); ++i) {
            used[i] = false;
        }
        dfs(nums, used);
        return res;
    }
};

int main() {

    return 0;
}